# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Print ISSN corresponding to given journal name
"""

__revision__ = "$Id$"

import pprint
import urllib
import sys
import re
import getopt
from invenio.search_engine import \
     get_fieldvalues, \
     perform_request_search
from invenio.config import CFG_CERN_SITE

if CFG_CERN_SITE:
    journal_name_tag = '773__p'
else:
    journal_name_tag = '909C4p'

issns = {   'aapps bull.': '0218-2203',
            'account. manag. inf. technol.': '0959-8022',
            'acm comput. surv.': '0360-0300',
            'acm sigplan not.': '0362-1340',
            'acm trans. comput. syst.': '0734-2071',
            'acm trans. comput.-hum. interact.': '1073-0516',
            'acm trans. database syst.': '0362-5915',
            'acm trans. graph.': '0730-0301',
            'acm trans. inf. syst. secur.': '1094-9224',
            'acm trans. internet technol.': '1533-5399',
            'acm trans. math. softw.': '0098-3500',
            'acm trans. program. lang. syst.': '0164-0925',
            'acm trans. storage': '1553-3077',
            'acta appl. math.': '1572-9036',
            'acta arith.': '1730-6264',
            'acta fac. rerum nat. univ. comen.: math.': '0373-8183',
            'acta math. appl. sin.': '1618-3932',
            'acta math. hung.': '1588-2632',
            'acta mech. sin.': '1614-3116',
            'acta mech. solida sin.': '1860-2134',
            'acta phys. pol. a': '0587-4246',
            'ad hoc netw.': '1570-8705',
            'adsorption': '1572-8757',
            'adv. cement based mater.': '1065-7355',
            'adv. colloid interface sci.': '0001-8686',
            'adv. compos. mater.': '1568-5519',
            'adv. eng. inform.': '1474-0346',
            'adv. eng. mater.': '1527-2648',
            'adv. geom.': '1615-715X',
            'adv. mater.': '1521-4095',
            'adv. math.': '0001-8708',
            'adv. perform. mater.': '1572-8765',
            'adv. powder technol.': '1568-5527',
            'adv. robot.': '1568-5535',
            'air space eur.': '1290-0958',
            'algebr. represent. theory': '1572-9079',
            'anal. math.': '0133-3852',
            'analog integr. circuits signal process.': '0925-1030',
            'angew. chem.': '1521-3757',
            'angew. chem. int. ed.': '1521-3773',
            'ann. glob. anal. geom.': '0232-704X',
            'ann. inst. stat. math.': '0020-3157',
            'ann. mat. pura appl.': '1618-1891',
            'ann. math. artif. intell.': '1012-2443',
            'ann. oper. res.': '1572-9338',
            'ann. phys. (san diego)': '0003-4916',
            'ann. phys. (weinheim)': '1521-3889',
            'ann. pol. math.': '1730-6272',
            'ann. sci. ec. norm. sup\xc3\xa9r.': '0012-9593',
            'ann. softw. eng.': '1573-7489',
            'annu. rev. nucl. part. sci.': '0163-8998',
            'appl. compos. mater.': '0929-189X',
            'appl. intell.': '0924-669X',
            'appl. math.': '0862-7940',
            'appl. math. electron. notes': '1607-2510',
            'appl. phys.': '0340-3793',
            'appl. soft comput.': '1568-4946',
            'appl. stoch. models bus. ind.': '1526-4025',
            'appl. supercond.': '0964-1807',
            'appl. surf. sci.': '0378-5963',
            'approx. theory. appl.': '1000-9221',
            'arch. mus. inform.': '1573-7500',
            'arch. sci.': '1573-7519',
            'ariadne': '1361-3200',
            'artif. intell. rev.': '0269-2821',
            'artif. life robot.': '1614-7456',
            'asimmetrie': '1827-1383',
            'astron. educ. rev.': '1539-1515',
            'astron. q.': '0364-9229',
            'astrophys. space sci.': '1572-946X',
            'astrophys. space sci. trans.': '1810-6536',
            'astrophysics': '1573-8191',
            'at. data nucl. data tables': '0092-640X',
            'at. energy': '1573-8205',
            'atom': '0004-7015',
            'autom. remote control.': '0005-1179',
            'autom. softw. eng.': '0928-8910',
            'auton. agents multi-agent syst.': '1387-2532',
            'auton. robots': '0929-5593',
            'banach cent. publ.': '1730-6299',
            'ber. bunsenges. phys. chem.': '0005-9021',
            'ber. wiss.gesch.': '1522-2365',
            'bioelectromagnetics': '1521-186X',
            'biom. j.': '1521-4036',
            'biomed. eng.': '0006-3398',
            'biophys. chem.': '0301-4622',
            'biosens. bioelecton.': '0956-5663',
            'bol. asoc. math. venez.': '1315-4125',
            'br. j. appl. phys.': '0508-3443',
            'bt technol. j.': '1358-3948',
            'bulg. j. phys.': '1310-0157',
            'bull. earthq. eng.': '1573-1456',
            'bull. soc. math. fr.': '0037-9484',
            'bull. union phys.': '0366-3878',
            'bus. strategy environ.': '1099-0836',
            'c. r. acad. sci., 2b': '1620-7742',
            'c. r. mech.': '1631-0721',
            'c. r. phys.': '1631-0705',
            'can. j. electr. comput. eng.': '0840-8688',
            'cas. pest. mat.': '0862-7959',
            'catal. lett.': '1572-879X',
            'celest. mech. dyn. astron.': '1572-9478',
            'chem. mater.': '1520-5002',
            'chem. vap. depos.': '1521-3862',
            'chemphyschem': '1439-7641',
            'chin. astron.': '0146-6364',
            'chin. librariansh.': '1089-4667',
            'chin. opt. lett.': '1671-7694',
            'chin. phys.': '1741-4199',
            'chin. phys. lett.': '0256-307X',
            'circuit world': '0305-6120',
            'circuits syst. signal process.': '1531-5878',
            'clean technol. environ. policy': '1618-9558',
            'clefs cea': '0298-6248',
            'clin. phys. physiol. meas.': '0143-0815',
            'cluster comput.': '1386-7857',
            'coastal eng.': '0378-3839',
            'colloid j.': '1608-3067',
            'colloq. math.': '1730-6310',
            'comments mod. phys.': '1560-5892',
            'commun. acm': '0001-0782',
            'commun. nonlinear sci. numer. simul.': '1007-5704',
            'commun. pure appl. math.': '1097-0312',
            'commun. soc.: dig. news events interest commun. eng.': '0094-5579',
            'complexity': '1099-0526',
            'compos. math.': '0010-437X',
            'composites': '0010-4361',
            'comput. archit. news': '0163-5964',
            'comput. bull.': '0010-4531',
            'comput. chem. eng.': '0098-1354',
            'comput. commun. rev.': '0146-4833',
            'comput. graph.': '0097-8930',
            'comput. humanit.': '1572-8412',
            'comput. ind. eng.': '0360-8352',
            'comput. integr. manuf. syst.': '0951-5240',
            'comput. math. model.': '1046-283X',
            'comput. math. organ. theory': '1381-298X',
            'comput. netw. isdn syst.': '0169-7552',
            'comput. optim. appl.': '0926-6003',
            'comput. phys. rep.': '0167-7977',
            'comput. soc.': '0095-2737',
            'comput. softw.': '0289-6540',
            'comput. speech lang.': '0885-2308',
            'comput. support. coop. work': '0925-9724',
            'comput. vis. image underst.': '1077-3142',
            'computer': '0018-9162',
            'concurr. comput.: pract. exp.': '1532-0634',
            'concurr.: pract. exp.': '1096-9128',
            'constraints': '1572-9354',
            'contact context': '1547-8890',
            'contrib. plasma phys.': '1521-3986',
            'cosm. res.': '0010-9525',
            'cost eng. j.': '0274-9626',
            'cryst. growth des.': '1528-7483',
            'cryst. res. technol.': '1521-4079',
            'cultiv. interact.': '1471-3225',
            'curr. appl. phys.': '1567-1739',
            'curr. opin. colloid. interface sci.': '1359-0294',
            'cybermetrics': '1137-5019',
            'cybern. syst. anal.': '1060-0396',
            'czechoslov. j. phys.': '1572-9486',
            'czechoslov. math. j.': '0011-4642',
            'data base adv. inf. syst.': '0095-0033',
            'data min. knowl. discov.': '1384-5810',
            'data sci. j.': '1683-1470',
            'des. autom. embed. syst.': '1572-8080',
            'des. codes cryptogr.': '0925-1022',
            'des. monomers polym.': '1568-5551',
            'differ. equ.': '0012-2116',
            'differ. geom.': '1454-511X',
            'digit. signal process.': '1051-2004',
            'discrete event dyn. syst.': '1573-7594',
            'distrib. parallel databases': '0926-8272',
            'documentaliste': '0012-4508',
            'dokl. phys. chem.': '0012-5016',
            'dyn. control': '1573-8450',
            'e-polymers': '1618-7229',
            'e-streams': '1098-4399',
            'earth moon planets': '0167-9295',
            'ec compet. policy newsl.': '1025-2266',
            'educ. inf. technol.': '1360-2357',
            'educ. stud. math.': '1573-0816',
            'egypt. j. solids': '1012-5566',
            'electrodepos. surf. treat.': '0300-9416',
            'electron microsc. rev.': '0892-0354',
            'electron. j. comb.': '1027-5487',
            'electron. j. theor. phys.': '1729-5254',
            'electron. libr.': '0264-0473',
            'electron. res. announc. am. math. soc.': '1079-6762',
            'electron. trans. artif. intell.': '1403-204X',
            'empir. softw. eng.': '1382-3256',
            'entropy': '1099-4300',
            'environ. qual. manag.': '1520-6483',
            'environmetrics': '1099-095X',
            'epj a direct': '1435-3725',
            'epj c direct': '1435-3725',
            'epj e direct': '1435-3725',
            'eso astrophys. symp.': '1611-6143',
            'ethics inf. technol.': '1572-8439',
            'etri j.': '1225-6463',
            'eur. environ.': '1099-0976',
            'eur. j. solid state inorg. chem.': '0992-4361',
            'eur. trans. electr. power': '1546-3109',
            'eur. union': '1472-3395',
            'eurasip j. wirel. commun. netw.': '1687-1499',
            'exergy': '1164-0235',
            'exp. astron.': '1572-9508',
            'extremes': '1572-915X',
            'fire technol.': '1572-8099',
            'fluid dyn.': '1573-8507',
            'form. methods syst. des.': '1572-8102',
            'forschung': '1522-2357',
            'fortran forum': '1061-7264',
            'fortschr. phys.': '1521-3978',
            'found. phys.': '0015-9018',
            'found. phys. lett.': '0894-9875',
            'free online scholarsh. newsl.': '1535-7848',
            'freepint newsl.': '1460-7239',
            'frontiers (swindon)': '1460-5600',
            'fuel cells': '1615-6854',
            'funct. anal. appl.': '0016-2663',
            'fundam. math.': '1730-6329',
            'fuzzy optim. decis. mak.': '1573-2908',
            'gaz. vide': '1638-802X',
            'gen. relativ. gravit.': '1572-9532',
            'geoinformatica': '1384-6175',
            'germ. res.': '1522-2322',
            'glass ceram.': '1573-8515',
            'gps solut.': '1521-1886',
            'graph. models image process.': '1077-3169',
            'heat recovery syst. chp': '0890-4332',
            'high energy chem.': '1608-3148',
            'high energy density phys.': '1574-1818',
            'high energy phys. nucl. phys. (beijing)': '0254-3052',
            'high temp.': '0018-151X',
            'hit j. sci. eng.': '1565-5008',
            'icarus': '0019-1035',
            'icsti forum': '1018-9580',
            'ieee aerosp. electron. syst. mag.': '0885-8985',
            'ieee ann. hist. comput.': '1058-6180',
            'ieee antennas propag. mag.': '1045-9243',
            'ieee antennas wirel. propag. lett.': '1536-1225',
            'ieee assp mag.': '0740-7467',
            'ieee circuits devices mag.': '8755-3996',
            'ieee circuits syst. mag.': '1531-636X',
            'ieee commun. lett.': '1089-7798',
            'ieee commun. mag.': '0163-6804',
            'ieee comput. appl. power': '0895-0156',
            'ieee comput. graph. appl.': '0272-1716',
            'ieee comput. sci. eng.': '1070-9924',
            'ieee concurr.': '1092-3063',
            'ieee control syst. mag.': '0272-1708',
            'ieee des. test comput.': '0740-7475',
            'ieee distrib. syst. online': '1541-4922',
            'ieee electr. insul. mag.': '0883-7554',
            'ieee electron device lett.': '0741-3106',
            'ieee eng. med. biol. mag.': '0739-5175',
            'ieee expert mag.': '0885-9000',
            'ieee instrum. measur. mag.': '1094-6969',
            'ieee intell. syst.': '1541-1672',
            'ieee intell. syst. appl.': '1094-7167',
            'ieee internet comput.': '1089-7801',
            'ieee j. ocean. eng.': '0364-9059',
            'ieee j. quantum electron.': '0018-9197',
            'ieee j. robot. autom.': '0882-4967',
            'ieee j. sel. areas commun.': '0733-8716',
            'ieee j. sel. top. quantum electron.': '1077-260X',
            'ieee j. solid state circuits': '0018-9200',
            'ieee lcs': '1045-9235',
            'ieee lts': '1055-6877',
            'ieee micro': '0272-1732',
            'ieee microw. guid. wave lett.': '1051-8207',
            'ieee microw. mag.': '1527-3342',
            'ieee microw. wirel. compon. lett.': '1531-1309',
            'ieee multimed.': '1070-986X',
            'ieee netw.': '0890-8044',
            'ieee parallel distrib. technol.: syst. appl.': '1063-6552',
            'ieee pers. commun.': '1070-9916',
            'ieee pervasive comput.': '1536-1268',
            'ieee photonics technol. lett.': '1041-1135',
            'ieee potentials': '0278-6648',
            'ieee power electron. lett.': '1540-7985',
            'ieee power energy mag.': '1540-7977',
            'ieee power eng. rev.': '0272-1724',
            'ieee robot. autom. mag.': '1070-9932',
            'ieee secur. priv. mag.': '1540-7993',
            'ieee sens. j.': '1530-437X',
            'ieee signal process. lett.': '1070-9908',
            'ieee signal process. mag.': '1053-5888',
            'ieee softw.': '0740-7459',
            'ieee spectr.': '0018-9235',
            'ieee technol. soc. mag.': '0278-0097',
            'ieee trans. acoust. speech signal process.': '0096-3518',
            'ieee trans. adv. packag.': '1521-3323',
            'ieee trans. aerosp. electron. syst.': '0018-9251',
            'ieee trans. antennas propag.': '0018-926X',
            'ieee trans. appl. supercond.': '1051-8223',
            'ieee trans. audio': '0096-1620',
            'ieee trans. audio electroacoust.': '0018-9278',
            'ieee trans. audio speech lang. process.': '1558-7916',
            'ieee trans. autom. sci. eng.': '1545-5955',
            'ieee trans. automat. control': '0018-9286',
            'ieee trans. biomed. eng.': '0018-9294',
            'ieee trans. broadcast.': '0018-9316',
            'ieee trans. circuits syst.': '0098-4094',
            'ieee trans. circuits syst. video technol.': '1051-8215',
            'ieee trans. circuits syst., i': '1057-7122',
            'ieee trans. circuits syst., ii': '1057-7130',
            'ieee trans. commun.': '0090-6778',
            'ieee trans. compon. hybrids manuf. technol.': '0148-6411',
            'ieee trans. compon. packag. manuf. technol. a': '1070-9886',
            'ieee trans. compon. packag. manuf. technol. b': '1070-9894',
            'ieee trans. compon. packag. manuf. technol. c': '1083-4400',
            'ieee trans. compon. packag. technol.': '1521-3331',
            'ieee trans. compon. parts': '0097-6601',
            'ieee trans. comput.': '0018-9340',
            'ieee trans. comput.-aided des. integrat. circuits syst.': '0278-0070',
            'ieee trans. consum. electron.': '0098-3063',
            'ieee trans. control syst. technol.': '1063-6536',
            'ieee trans. dependable secur. comput.': '1545-5971',
            'ieee trans. device mater. reliab.': '1530-4388',
            'ieee trans. dielectr. electr. insul.': '1070-9878',
            'ieee trans. educ.': '0018-9359',
            'ieee trans. electr. insul.': '0018-9367',
            'ieee trans. electromagn. compat.': '0018-9375',
            'ieee trans. electron devices': '0018-9383',
            'ieee trans. electron. packag. manuf.': '1521-334X',
            'ieee trans. energy convers.': '0885-8969',
            'ieee trans. eng. manag.': '0018-9391',
            'ieee trans. evol. comput.': '1089-778X',
            'ieee trans. fuzzy syst.': '1063-6706',
            'ieee trans. geosci. remote sens.': '0196-2892',
            'ieee trans. image process.': '1057-7149',
            'ieee trans. ind. appl.': '0093-9994',
            'ieee trans. ind. electron.': '0278-0046',
            'ieee trans. ind. inform.': '1551-3203',
            'ieee trans. inf. technol. biomed.': '1089-7771',
            'ieee trans. inf. theory': '0018-9448',
            'ieee trans. instrum. meas.': '0018-9456',
            'ieee trans. intell. transp. syst.': '1524-9050',
            'ieee trans. knowl. data eng.': '1041-4347',
            'ieee trans. magn.': '0018-9464',
            'ieee trans. manuf. technol.': '0046-838X',
            'ieee trans. med. imaging': '0278-0062',
            'ieee trans. microw. theory tech.': '0018-9480',
            'ieee trans. mob. comput.': '1536-1233',
            'ieee trans. multimed.': '1520-9210',
            'ieee trans. nanobiosci.': '1536-1241',
            'ieee trans. nanotechnol.': '1536-125X',
            'ieee trans. neural netw.': '1045-9227',
            'ieee trans. neural syst. rehabil. eng.': '1534-4320',
            'ieee trans. nucl. sci.': '0018-9499',
            'ieee trans. parallel distrib. syst.': '1045-9219',
            'ieee trans. parts hybrids packag.': '0361-1000',
            'ieee trans. parts mater. packag.': '0018-9502',
            'ieee trans. pattern anal. mach. intell.': '0162-8828',
            'ieee trans. plasma sci.': '0093-3813',
            'ieee trans. power deliv.': '0885-8977',
            'ieee trans. power electron.': '0885-8993',
            'ieee trans. power syst.': '0885-8950',
            'ieee trans. prod. eng. prod.': '0097-4544',
            'ieee trans. prof. commun.': '0361-1434',
            'ieee trans. rehabil. eng.': '1063-6528',
            'ieee trans. reliab.': '0018-9529',
            'ieee trans. robot.': '1552-3098',
            'ieee trans. robot. autom.': '1042-296X',
            'ieee trans. semicond. manuf.': '0894-6507',
            'ieee trans. signal process.': '1053-587X',
            'ieee trans. softw. eng.': '0098-5589',
            'ieee trans. sonics ultrason.': '0018-9537',
            'ieee trans. speech audio process.': '1063-6676',
            'ieee trans. syst. man cybern.': '0018-9472',
            'ieee trans. syst. man cybern. a': '1083-4427',
            'ieee trans. syst. man cybern. b': '1083-4419',
            'ieee trans. syst. man cybern. c': '1094-6977',
            'ieee trans. ultrason. eng.': '0893-6706',
            'ieee trans. ultrason., ferroelectr. freq. control': '0885-3010',
            'ieee trans. veh. technol.': '0018-9545',
            'ieee trans. very large scale integr. (vlsi) syst.': '1063-8210',
            'ieee trans. vis. comput. graph.': '1077-2626',
            'ieee trans. wirel. commun.': '1536-1276',
            'ieee wirel. commun.': '1536-1284',
            'ieee/acm trans. netw.': '1063-6692',
            'ieee/asme trans. mechatron.': '1083-4435',
            'iii-vs rev.': '0961-1290',
            'inf. bull. var. stars': '1587-2440',
            'inf. manag.': '0378-7206',
            'inf. organ.': '1471-7727',
            'inf. process. manag.': '0306-4573',
            'inf. res.': '1368-1613',
            'inf. retr.': '1386-4564',
            'inf. sci. appl.': '1069-0115',
            'inf. syst. e-bus. manag.': '1617-9854',
            'inf. syst. front.': '1387-3326',
            'inf. technol. disabil.': '1073-5727',
            'inf. technol. manag.': '1385-951X',
            'infeuro': '1027-930X',
            'infrared phys.': '0020-0891',
            'innov. syst. softw. eng.': '1614-5054',
            'innov. teach. learn. inf. comput. sci.': '1473-1707',
            'innov. technol. transf.': '1013-6452',
            'innov. transf. technol.': '1025-692X',
            'inorg. mater.': '1608-3172',
            'instrum. exp. tech.': '0020-4412',
            'int. appl. mech.': '1573-8582',
            'int. insolv. rev.': '1099-1107',
            'int. j. appl. electromagn. mech.': '1383-5416',
            'int. j. appl. math. comput. sci.': '1641-876X',
            'int. j. appl. radiat. isot.': '0020-708X',
            'int. j. comput. math. learn.': '1382-3892',
            'int. j. comput. vis.': '0920-9429',
            'int. j. des. comput.': '1329-7147',
            'int. j. electron. commun.': '1434-8411',
            'int. j. electron. commun. (aeu)': '1434-8411',
            'int. j. fract.': '0376-9429',
            'int. j. hum.-comput. stud.': '1071-5819',
            'int. j. infrared millim. waves': '1572-9559',
            'int. j. intell. syst.': '1098-111X',
            'int. j. mass spectrom.': '1387-3806',
            'int. j. mass spectrom. ion process.': '0168-1176',
            'int. j. mod. phys. d': '0218-2718',
            'int. j. mod. phys. e': '0218-3013',
            'int. j. parallel program.': '0885-7458',
            'int. j. pattern recognit. artif. intell.': '0218-0014',
            'int. j. prod. econ.': '0925-5273',
            'int. j. radiat. appl. instrum. a': '0883-2889',
            'int. j. radiat. appl. instrum. d': '1359-0189',
            'int. j. radiat. phys. chem. (1969-76)': '0020-7055',
            'int. j. radiat. phys. chem., c': '1359-0197',
            'int. j. rock mech. min. sci.': '1365-1609',
            'int. j. technol. des. educ.': '0957-7572',
            'int. j. theor. phys.': '1572-9575',
            'int. j. therm. sci.': '1290-0729',
            'int. j. thermophys.': '1572-9567',
            'int. j. wirel. inf. netw.': '1068-9605',
            'intel. artif.': '1137-3601',
            'interact. multimed. electron. j. comput. enhanc. learn.': '1525-9102',
            'interface sci.': '0927-7056',
            'ipn sci.': '1622-5120',
            'ire trans. audio': '0096-1981',
            'ire trans. autom. control': '0096-199X',
            'ire trans. circuit theory': '0098-4094',
            'ire trans. compon. parts': '0096-2422',
            'ire trans. prod. eng. prod.': '0096-1779',
            'ire trans. prod. tech.': '0096-1760',
            'ire trans. ultrason. eng.': '0096-1019',
            'it archit.': '1557-2145',
            'it prof.': '1520-9202',
            'itbm-rbm': '1297-9562',
            'itbm-rbm news': '1297-9570',
            'itnow': '1746-5702',
            'j. acm assoc. comput. mach.': '0004-5411',
            'j. adhes. sci. technol.': '1568-5616',
            'j. algebr. comb.': '0925-9899',
            'j. am. soc. inf. sci.': '1097-4571',
            'j. am. soc. inf. sci. technol.': '1532-2890',
            'j. anal. chem.': '1608-3199',
            'j. appl. clin. med. phys.': '1526-9914',
            'j. appl. electrochem.': '0021-891X',
            'j. appl. mech. tech. phys.': '1573-8620',
            'j. appl. spectrosc.': '1573-8647',
            'j. artif. intell. res.': '1076-9757',
            'j. astrophys. astron.': '0250-6335',
            'j. autom. reason.': '0168-7433',
            'j. biomater. sci., polym. ed.': '1568-5624',
            'j. braz. comput. soc.': '0104-6500',
            'j. chem. doc.': '1961-1974',
            'j. chem. eng. data': '1520-5134',
            'j. chemom.': '1099-128X',
            'j. colloid interface sci.': '0021-9797',
            'j. comput. aided mater. des.': '0928-1045',
            'j. comput. anal. appl.': '1521-1398',
            'j. comput. electron.': '1569-8025',
            'j. comput. neurosci.': '0929-5313',
            'j. comput. phys.': '0021-9991',
            'j. comput. sci. technol.': '1860-4749',
            'j. comput.- mediat. commun.': '1083-6101',
            'j. corros. sci. eng.': '1466-8858',
            'j. cosmol. astropart. phys.': '1475-7516',
            'j. data sci.': '1683-8602',
            'j. des. commun.': '1137-3601',
            'j. digit. inf.': '1368-7506',
            'j. disp. technol.': '1551-319X',
            'j. dyn. control syst.': '1079-2724',
            'j. dyn. differ. equ.': '1040-7294',
            'j. elast.': '1573-2681',
            'j. electroceram.': '1385-3449',
            'j. electromagn. waves appl.': '1569-3937',
            'j. electron. test.': '0923-8174',
            'j. eng. math.': '0022-0833',
            'j. eng. phys. thermophys.': '1573-871X',
            'j. fluids struct.': '0889-9746',
            'j. fourier anal. appl.': '1531-5851',
            'j. fusion energy': '1572-9591',
            'j. geophys. eng.': '1742-2132',
            'j. glob. optim.': '0925-5001',
            'j. grid comput.': '1572-9814',
            'j. heuristics': '1381-1231',
            'j. high energy phys.': '1126-6708',
            'j. instrum.': '1748-0221',
            'j. intell. inf. syst.': '0925-9902',
            'j. intell. manuf.': '1572-8145',
            'j. intell. robot. syst.': '1573-0409',
            'j. interlibr. loan doc. deliv. electron. reserve': '1072-303X',
            'j. jpn. stat. soc.': '1348-6365',
            'j. lightwave technol.': '0733-8724',
            'j. log. algebr. program.': '1567-8326',
            'j. log. lang. inf.': '1572-9583',
            'j. low temp. phys.': '1573-7357',
            'j. magn. reson.': '1090-7807',
            'j. magn. reson. a': '1064-1858',
            'j. magn. reson. b': '1064-1866',
            'j. magn. reson. imag.': '1522-2586',
            'j. mater. cycles waste manag.': '1611-8227',
            'j. mater. sci.': '0022-2461',
            'j. mater. sci. lett.': '0261-8028',
            'j. mater. sci.: mater. electron.': '0957-4522',
            'j. mater. sci.: mater. med.': '0957-4530',
            'j. mater. synth. process.': '1573-4870',
            'j. math. imaging vis.': '0924-9907',
            'j. math. model. algorithms': '1570-1166',
            'j. math. sci.': '1072-3374',
            'j. math. teach. educ.': '1573-1820',
            'j. microcomput. appl.': '0745-7138',
            'j. microelectromech. syst.': '1057-7157',
            'j. micromechatron.': '1568-5632',
            'j. nanomater.': '1687-4129',
            'j. nanopart. res.': '1572-896X',
            'j. netw. comput. appl.': '1084-8045',
            'j. netw. syst. manag.': '1064-7570',
            'j. neural eng.': '1741-2560',
            'j. non-newton. fluid mech.': '0377-0257',
            'j. nondestruct. eval.': '0195-9298',
            'j. nucl. energy, c': '0368-3281',
            'j. object technol.': '1660-1769',
            'j. oper. manage.': '0272-6963',
            'j. opt.': '0150-536X',
            'j. opt. fiber commun. rep.': '1619-8638',
            'j. opt. netw.': '1536-5379',
            'j. opt. technol.': '1070-9762',
            'j. optim. theory appl.': '0022-3239',
            'j. parallel distrib. comput.': '0743-7315',
            'j. phys. c': '0022-3719',
            'j. phys. chem. a': '0092-7325',
            'j. phys. chem. b': '0092-7325',
            'j. phys. f': '0305-4608',
            'j. phys. stud.': '1027-4642',
            'j. phys.: conf. ser.': '1742-6596',
            'j. polym. res.': '1022-9760',
            'j. porous mater.': '1573-4854',
            'j. product. anal.': '1573-0441',
            'j. radiat. res.': '0449-3060',
            'j. radioanal. nucl. chem.': '1588-2780',
            'j. res. natl. inst. stand. technol.': '1044-677X',
            'j. res. pract.': '1712-851X',
            'j. russ. laser res.': '1573-8760',
            'j. sci. commun.': '1824-2049',
            'j. sci. comput.': '0885-7474',
            'j. sci. instrum.': '0950-7671',
            'j. soc. radiol. prot.': '0260-2814',
            'j. softw. maint. evol.: res. pract.': '1532-0618',
            'j. softw. maint.: res. pract.': '1096-908X',
            'j. sound vib.': '0022-460X',
            'j. south. acad. spec. librariansh.': '1525-321X',
            'j. stat. mech., theory exp.': '1742-5468',
            'j. stat. phys.': '1572-9613',
            'j. stat. softw.': '1548-7660',
            'j. strain anal. eng. des.': '0309-3247',
            'j. supercomput.': '0920-8542',
            'j. supercond.': '1572-9605',
            'j. supercond. novel magn.': '1557-1939',
            'j. supercrit. fluids': '0896-8446',
            'j. syst. integr.': '1573-8787',
            'j. technol. transf.': '0829-9912',
            'j. theor. probab.': '0894-9840',
            'j. therm. anal. calorim.': '1572-8943',
            'j. vis. commun. image represent.': '1047-3203',
            'j. vis. comput. animat.': '1099-1778',
            'j. vlsi signal process. syst. signal image video technol.': '0922-5773',
            'jpn. j. appl. phys.': '1347-4065',
            'k-theory': '1573-0514',
            'katharine sharp rev.': '1083-5261',
            'kek news': '1343-3547',
            'lasers med. sci.': '1435-604X',
            'lett. math. phys.': '1573-0530',
            'libr. philos. pract.': '1522-0222',
            'linux j.': '1075-3583',
            'lith. math. j.': '0363-1672',
            'living rev. sol. phys.': '1614-4961',
            'low temp. phys.': '1063-777X',
            'mach. learn.': '0885-6125',
            'macromol. chem. phys.': '1521-3935',
            'macromol. mater. eng.': '1439-2054',
            'macromol. rapid commun.': '1521-3927',
            'macromol. symp.': '1521-3900',
            'macromol. theory simul.': '1521-3919',
            'magma magn. reson. mater. phys. biol. med.': '1352-8661',
            'magn. reson. imaging': '0730-725X',
            'mater. sci.': '1068-820X',
            'mater. technol.': '1580-3414',
            'math. notes': '0001-4346',
            'math. phys. anal. geom.': '1385-0172',
            'math. probl. eng.': '1563-5147',
            'math. scand.': '0025-5521',
            'mc j.': '1069-6792',
            'meas. tech.': '0543-1972',
            'meccanica': '1572-9648',
            'mech. compos. mater.': '1573-8922',
            'mech. syst. signal process.': '0888-3270',
            'mech. time-depend. mater.': '1573-2738',
            'med. phys.': '0094-2405',
            'mediterr. j. math.': '1660-5454',
            'met. sci. heat treat.': '0026-0673',
            'metallurgist': '1573-8892',
            'methodol. comput. appl. probab.': '1387-5841',
            'metrika': '1436-5057',
            'metrologia': '1681-7575',
            'microfluid. nanofluid.': '1613-4990',
            'micromater. nanomater.': '1619-2486',
            'micron': '0968-4328',
            'micron (1969-83) [online version]': '0047-7206',
            'micron microsc. acta': '0739-6260',
            'microw. rf': '0745-2993',
            'milan j. math.': '1424-9294',
            'minds mach.': '1572-8641',
            'minerva': '0026-4695',
            'mo. j. math. sci.': '0899-6180',
            'mob. netw. appl.': '1572-8153',
            'mol. eng.': '1572-8951',
            'monogr. mat.': '0077-0507',
            'monte carlo methods appl.': '1569-3961',
            'mrs bull.': '0883-7694',
            'multibody syst. dyn.': '1573-272X',
            'multidimens. syst. signal process.': '0923-6082',
            'multimed. tools appl.': '1380-7501',
            'm\xc3\xa9c. ind.': '1296-2139',
            'nagoya math. j.': '0027-7630',
            'netw. comput.': '1046-4468',
            'networks': '1097-0037',
            'neural process. lett.': '1370-4621',
            'neutron news': '1044-8632',
            'new dir. high. educ.': '1522-2322',
            'new dir. instit. res.': '1536-075X',
            'new dir. stud. serv.': '1536-0695',
            'new dir. teach. learn.': '1536-0768',
            'nexus netw. j.': '1522-4600',
            'nonlinear dyn.': '1573-269X',
            'nonlinear phenom. complex syst.': '1561-4085',
            'nonprofit couns.': '1520-6785',
            'not. am. math. soc.': '1088-9477',
            'nouv. rev. opt.': '0335-7368',
            'nouv. rev. opt. appl.': '0029-4780',
            'ntm int. j. hist. ethics nat. sci. technol. med.': '1420-9144',
            'nucl. data sheets': '0090-3752',
            'nucl. data sheets, a': '0550-306X',
            'nucl. data sheets, b': '0090-550X',
            'nucl. eng. des. fusion': '0167-899X',
            'nucl. eng. technol.': '1738-5733',
            'nucl. fusion': '0029-5515',
            'nucl. instrum.': '0369-643X',
            'nucl. instrum. methods': '0029-554X',
            'nucl. instrum. methods phys. res.': '0167-5087',
            'nucl. instrum. methods phys. res., a': '0167-5087',
            'nucl. phys.': '0029-5582',
            'nucl. phys. news': '1050-6896',
            'nucl. struct. eng.': '0369-5816',
            'nucl. track detect.': '0145-224X',
            'nucl. tracks': '0735-245X',
            'nucl. tracks radiat. meas.': '0191-278X',
            'nucl. tracks radiat. meas. (1982-85)': '0735-245X',
            'nucl. tracks radiat. meas. (1993)': '0969-8078',
            'nukleonika': '1508-5791',
            'numer. algorithms': '1572-9265',
            'numer. methods partial differ. equ.': '1098-2426',
            'nuovo cimento, riv.': '0393-697X',
            'ocean dyn.': '1616-7228',
            'open syst. inf. dyn.': '1230-1612',
            'oper. syst. rev.': '0163-5980',
            'opt. fiber technol.': '1068-5200',
            'opt. netw. mag.': '1572-8161',
            'opt. photonics news': '1047-6938',
            'opt. quantum electron.': '0306-8919',
            'opt. rev.': '1349-9432',
            'opt. spectrosc.': '1562-6911',
            'opt. switch. netw.': '1573-4277',
            'opt. technol.': '0374-3926',
            'optik': '0030-4026',
            'optim. control appl. methods': '1099-1514',
            'optim. eng.': '1389-4420',
            'oxid. met.': '0030-770X',
            'packag. technol. sci.': '1099-1522',
            'pamm': '1617-7061',
            'part. part. syst. charact.': '1521-4117',
            'period. math. hung.': '1588-2829',
            'pers. technol.': '1433-3066',
            'pers. ubiquitous comput.': '1617-4917',
            'philips j. res.': '0165-5817',
            'photonic netw. commun.': '1572-8188',
            'photonics nanostruct., fundam. appl.': '1569-4410',
            'phys. biol.': '1478-3975',
            'phys. earth planet. inter.': '0031-9201',
            'phys. fluids (1958-88)': '0031-9171',
            'phys. j.': '0031-9279',
            'phys. j. indones. phys. soc.': '1410-8860',
            'phys. lett.': '0031-9163',
            'phys. lett., a': '0375-9601',
            'phys. lett., b': '0370-2693',
            'phys. life rev.': '1571-0645',
            'phys. rev.': '0031-899X',
            'phys. rev. (ser. i)': '0031-899X',
            'phys. rev. lett.': '0031-9007',
            'phys. rev. spec. top. phys. educ. res.': '1554-9178',
            'phys. rev., a': '1050-2947;',
            'phys. rev., b': '0163-1829',
            'phys. rev., c': '0556-2813',
            'phys. rev., d': '0556-2821',
            'phys. rev., e': '1063-651x',
            'phys. status solidi, c': '1610-1642',
            'phys. technol.': '0305-4624',
            'phys. unserer zeit': '1521-3943',
            'physica': '0031-8914',
            'physica b c': '0378-4363',
            'plasma chem. plasma process.': '1572-8986',
            'plasma phys.': '0032-1028',
            'plasmas ions': '1288-3255',
            'plasmas polym.': '1572-8978',
            'poiesis prax.': '1615-6617',
            'polym. gels netw.': '0966-7822',
            'powder metall. met. ceram.': '1068-1302',
            'power technol. eng.': '1570-1468',
            'prace mat.- fiz.': '0867-5570',
            'probab. surv.': '1549-5787',
            'probl. inf. transm.': '0032-9460',
            'proc. ieee': '0018-9219',
            'proc. indian acad. sci., math. sci.': '0253-4142',
            'proc. jpn. acad. a': '0386-2194',
            'proc. phys. soc. (1926-48)': '0959-5309',
            'proc. phys. soc. (1958-67)': '0370-1328',
            'proc. phys. soc. lond.': '1478-7814',
            'proc. phys. soc., a': '0370-1298',
            'proc. phys. soc., b': '0370-1301',
            'prog. cryst. growth charact.': '0146-3535',
            'prog. nucl. magn. reson. spectrosc.': '0079-6565',
            'prog. phys.': '1555-5615',
            'prog. theor. phys., suppl.': '0375-9687',
            'progr. struct. eng. mater.': '1528-2716',
            'program. comput. softw.': '0361-7688',
            'propellants explos. pyrotech.': '1521-4087',
            'prot. met.': '0033-1732',
            'publ. math. ihes': '1618-1913',
            'public underst. sci.': '1361-6609',
            'pure appl. opt.': '0963-9659',
            'qual. assur. j.': '1099-1786',
            'qual. reliab. eng. int.': '1099-1638',
            'quant. financ.': '1469-7688',
            'quantum inf. process.': '1570-0755',
            'quantum opt.': '0954-8998',
            'quantum semiclass. opt.': '1355-5111',
            'queueing syst.': '1572-9443',
            'radiat. phys. chem. (1977-85)': '0146-5724',
            'radiochemistry': '1608-3288',
            'radioisotopes': '0033-8303',
            'radiophys. quantum electron.': '1573-9120',
            'radioprotection': '1769-700X',
            'ramanujan j.': '1572-9303',
            'rbm-news': '0222-0776',
            'real time imaging': '1077-2014',
            'real time syst.': '0922-6443',
            'refract. ind. ceram.': '1083-4877',
            'reliab. comput.': '1385-3139',
            'rend. lincei': '1720-0768',
            'rend. lincei sci. fis. nat.': '1720-0776',
            'rend. semin. mat.': '0373-1243',
            'res. inf.': '1744-8026',
            'res. lang. comput.': '1572-8706',
            'res. nondestruct. eval.': '1432-2110',
            'rev. electron. suisse sci. inf.': '1661-1802',
            'rev. g\xc3\xa9n. therm.': '0035-3159',
            'rev. mex. fis.': '0035-001X',
            'rev. phys. chim. appl. ind.': '1153-9771',
            'rheol. acta': '1435-1528',
            'risonyt': '0108-0350',
            'rom. rep. phys.': '1221-1451',
            'rozpr. mat.': '0860-2581',
            'russ. j. electrochem.': '1023-1935',
            'russ. j. nondestruct. test.': '1061-8309',
            'russ. j. numer. anal. math. model.': '1569-3988',
            'russ. microelectron.': '1063-7397',
            'russ. phys. j.': '1573-9228',
            's. afr. j. inf. manag.': '1560-683X',
            'sankhya. indian j. stat.': '0036-4452',
            'sci. am.': '0036-8733',
            'sci. avenir': '0036-8636',
            'sci. educ.': '1098-237X',
            'sci. soils': '1432-9492',
            'sci. vie hors s\xc3\xa9r.': '0151-0282',
            'scientometrics': '0138-9130',
            'semicond. int.': '0163-3767',
            'semicond. phys. quantum electron. optoelectron.': '1605-6582',
            'semigroup forum': '0037-1912',
            'sens. actuators a': '0924-4247',
            'sens. actuators b': '0925-4005',
            'sens. update': '1616-8984',
            'sensors': '1424-8220',
            'ser. enews': '1476-0576',
            'serials': '0953-0460',
            'sib. math. j.': '0037-4466',
            'sigact news': '0163-5700',
            'sigbio newsl.': '0163-5697',
            'sigcse bull.': '0097-8418',
            'sigsam bull.': '0163-5824',
            'simul. model. pract. theory': '1569-190X',
            'single mol.': '1438-5171',
            'softw. eng. notes': '0163-5948',
            'softw. focus': '1529-7950',
            'softw. process: improv. pract.': '1099-1670',
            'softw. qual. j.': '0963-9314',
            'softw. syst. model.': '1619-1374',
            'softw. test. verif. reliab.': '1099-1689',
            'softw.- pract. exp.': '1097-024X',
            'sol. syst. res.': '0038-0946',
            'solaris': '1265-4876',
            'solid state sci.': '1293-2558',
            'space sci. rev.': '0038-6308',
            'sparc open access newsl.': '1546-7821',
            'stat. comput.': '0960-3174',
            'stat. methods appl.': '1613-981X',
            'stat. sci.': '0883-4237',
            'stnews': '1040-1229',
            'strength mater.': '1573-9325',
            'struct. des. tall build.': '1099-1794',
            'stud. hist. philos. mod. phys.': '1355-2198',
            'studia log.': '1572-8730',
            'studia math.': '1730-6337',
            'subsurf. sens. technol. appl.': '1573-9317',
            'superlattices microstruct.': '0749-6036',
            'surf. sci. lett.': '0167-2584',
            'surf. technol.': '0376-4583',
            'surv. high energy phys.': '0142-2413',
            'synthese': '1573-0964',
            'syst. comput. jpn.': '1520-684X',
            'syst. eng.': '1520-6858',
            'taiwan. j. math.': '1027-5487',
            'telecommun. syst.': '1018-4864',
            'theor. math. phys.': '1573-9333',
            'theory comput.': '1557-2862',
            'theory pract. object syst.': '1096-9942',
            'trans. ire prof. group commun. syst.': '0277-6243',
            'trans. ire prof. group compon. parts': '0096-2422',
            'trans. ire prof. group ultrason. eng.': '0277-626X',
            'trans. jpn. soc. artif. intell.': '1346-8030',
            'trans. opt. soc.': '1475-4878',
            'tribol. lett.': '1573-2711',
            'tsinghua sci. technol.': '1007-0214',
            'turk. j. math.': '1300-0098',
            'turk. j. phys.': '1300-0101',
            'ukr. math. j.': '0041-5995',
            'ultrason. imaging': '0161-7346',
            'univers. access inf. soc.': '1615-5297',
            'upgrade': '1684-5285',
            'user model. user adapt. interact.': '1573-1391',
            'uspekhi fiz. nauk': '0042-1294',
            'vak. forsch. prax.': '1522-2454',
            'vine': '1474-1032',
            'virtual real.': '1434-9957',
            'web semant.': '1570-8268',
            'weld. int.': '1573-9449',
            'wind energy': '1099-1824',
            'wirel. commun. mob. comput.': '1530-8677',
            'wirel. netw.': '1022-0038',
            'wirel. pers. commun.': '0929-6212',
            'world pat. inf.': '0172-2190',
            'world wide web': '1386-145X',
            'z. anal. anwend.': '0232-2064',
            'z. angew. math. mech.': '1521-4001',
            'z. krist.gr.': '0044-2968',
            'z. phys.': '0044-3328',
            'z. phys., c': '0170-9739'}

def format(bfo):
    """
    Returns the ISSN of the record, if known.<br/>
    Note that you HAVE to pre-generate the correspondances
    journal->ISSN if you want this element
    to return something (Run <code>python bfe_issn.py -h</code> to get help).
    """

    journal_name = bfo.field(journal_name_tag)

    # Here you might want to process journal name
    # by doing the same operation that has been
    # done when saving the mappings
    journal_name = journal_name.lower().strip()
    if journal_name.endswith("[online]"):
        journal_name = journal_name[:-8].rstrip()

    return issns.get(journal_name, '')

def build_issns_from_distant_site(url):
    """
    Retrieves the ISSNs from a distant Invenio system.
    Store the "journal name -> issn" relation.

    Normalize journal names a little bit:
        - strip whithespace chars (left and right)
        - all lower case
        - remove "[Online]" suffix

    Print the result as Python dict structure.

    @param url: the url to load issn from (in the *exact* form: http://www.mysite.com/)
    """
    ## Parse the results of the http request:
    ## http://cdsweb.cern.ch/search?cc=Periodicals&ot=022,210&of=tm&rg=9000

    pattern_field = re.compile(r'''
    \D*(?P<docid>\d*)              #document id
    \s(?P<tag>\d*)__\s\$\$a        #tag
     (?P<value>.*?)$               #value
      ''', re.IGNORECASE | re.DOTALL | re.VERBOSE)
    request = '/search?cc=Periodicals&ot=022,210&of=tm'
    try:
        fields = urllib.urlopen(url.rstrip('/') + request).readlines()
    except IOError:
        sys.stderr.write("Error: Could not connect to %s.\n" % url)
        sys.exit(0)

    last_doc_id = None
    last_issn = None

    built_issns = {}
    #built_issns = issns # Uncomment this to extend existing issns dict
                         # (e.g. in case of manual addition)
    for field in fields:
        result = pattern_field.search(field)
        if result:
            doc_id = result.group('docid')
            if doc_id != last_doc_id:
                # Reset saved ISSN if we parse new document
                last_issn = None

            tag = result.group('tag')
            if tag == '022':
                # Remember this ISSN
                last_issn = result.group('value')

            elif tag == '210' and last_issn is not None:
                # Found a journal name and issn exists.
                # Depending on how journal names are entered into the
                # database, you might want to do some processing
                # before saving:
                journal = result.group('value')
                journal = journal.lower().strip()
                if journal.endswith("[online]"):
                    journal = journal[:-8].rstrip()

                built_issns[journal] = last_issn

            last_doc_id = doc_id

    prtyp = pprint.PrettyPrinter(indent=4)
    prtyp.pprint(built_issns)

def build_issns_from_local_site():
    """
    Retrieves the ISSNs from the local database.
    Store the "journal name -> issn" relation.

    Normalize journal names a little bit:
        - strip whithespace chars (left and right)
        - all lower case
        - remove "[Online]" suffix

    Print the result as Python dict structure.
    """

    rec_id_list = perform_request_search(cc='Periodicals',
                                         of='id')
    built_issns = {}
    #built_issns = issns # Uncomment this to extend existing issns dict
                         # (e.g. in case of manual addition)
    for rec_id in rec_id_list:
        journal_name_list = get_fieldvalues(rec_id, '210__%')
        issn_list = get_fieldvalues(rec_id, '022__a')
        if issn_list:
            issn = issn_list[0] # There should be only one ISSN
            for journal_name in journal_name_list:
                # Depending on how journal names are entered into the database,
                # you might want to do some processing before saving:
                journal_name = journal_name.lower().strip()
                if journal_name.endswith("[online]"):
                    journal_name = journal_name[:-8].rstrip()

                built_issns[journal_name] = issn

    prtyp = pprint.PrettyPrinter(indent=4)
    prtyp.pprint(built_issns)

def print_info():
    """
    Info on element arguments
    """
    print """ Collects ISSN and corresponding journal names from local repository
 and prints archive as dict structure.

 Usage: python bfe_issn.py [Options] [url]
 Example: python bew_issn.py http://cdsweb.cern.ch/

 Options:
   -h, --help      print this help
   -u, --url       the URL to collect ISSN from
   -v, --version   print version number

 If 'url' is not given, collect from local database, using a faster method.

 Returned structure can then be copied into bfe_issn.py
 'format' function.
    """
if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hu:v",
                                   ["help",
                                    "url",
                                    "version"
                                    ])
    except getopt.error:
        print_info()
        sys.exit(0)

    url_arg = None
    for opt, opt_value in opts:

        if opt in ["-u", "--url"]:
            url_arg = opt_value
        elif opt in ["-v", "--version"]:
            print __revision__
            sys.exit(0)
        else:
            print_info()
            sys.exit(0)

    if url_arg is not None:
        build_issns_from_distant_site(url_arg)
    else:
        build_issns_from_local_site()
